﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AccCoreLib;
using Giraffe.Core.Common.Messengers;

namespace Giraffe.Core.ICQ
{
    public class IcqContact: IMessengerContact
    {
        private AccUserState _icqUserState;

        public IcqContact(string id)
        {
            ID = id;
            Name = ID;
            IcqUserState = AccUserState.AccUserState_Unknown;
        }

        internal AccUserState IcqUserState
        {
            get { return _icqUserState; }
            set
            {
                if (value == _icqUserState) return;

                _icqUserState = value;
                
                Action stateChanged = StateChanged;
                if (stateChanged != null)
                {
                    stateChanged();
                }
            }
        }

        public event Action StateChanged;
        public string ID
        {
            get; private set;
        }

        public string Name 
        {
            get; set;
        }


        public string GroupName
        {
            get; set;
        }

        public ContactStateEnum State
        {
            get
            {
                switch (IcqUserState)
                {
                    case AccUserState.AccUserState_Unknown: return ContactStateEnum.Unknown;
                    case AccUserState.AccUserState_Offline: return ContactStateEnum.Offline;
                    case AccUserState.AccUserState_Idle:    return ContactStateEnum.Idle;
                    case AccUserState.AccUserState_Away:    return ContactStateEnum.Away;
                    case AccUserState.AccUserState_Online:  return ContactStateEnum.Online;

                    default: return ContactStateEnum.Unknown;
                }
            }
        }

        public MessengerType Messenger
        {
            get { return MessengerType.Icq; }
        }
    }
}
